import { ref } from "vue";
export const inputSearchHandler = () => {
     // 显示搜索到的值
    const matchedValue = ref([]);
    const SearchHandler = (arr, searchobj,includesName) => {
        // 清除之前的匹配值 
        matchedValue.value = [];
        if (searchobj.value.trim()) {
            // 遍历数据数组查找匹配项
            for (const item of arr) {
                if (includesName?item[includesName].includes(searchobj.value.trim()):item.label.includes(searchobj.value.trim())) {
                    matchedValue.value.push(item)
                }
            }
        } else {
            // 如果输入为空，则显示原先的值  
            matchedValue.value = arr
        }
        return  matchedValue.value
    }
    return {
        matchedValue,
        SearchHandler
    };
};